package ThreadDemo;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 34255
 * Date: 2024-10-09
 * Time: 21:58
 */
class MyThread extends Thread{//创建子类继承Thread
    @Override
    //线程执行的内容
    public void run(){//重写run方法，编写需要实现的逻辑
        while(true){
            System.out.println("hello Thread");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
public class demo1 {
    public static void main(String[] args) {//一个进程至少包含一个线程，main方法即是一个线程
        //实例化Thread类
        Thread myThread = new MyThread();
        myThread.start();//创建线程，JVM会调用底层操作系统提供的API创建线程，并执行线程内容

        while(true){
            System.out.println("hello main");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
